package com.ruoyi.favorite.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.place.domain.Place;
import com.ruoyi.place.mapper.PlaceMapper;
import com.ruoyi.product.domain.Product;
import com.ruoyi.product.mapper.ProductMapper;
import com.ruoyi.user.domain.User;
import com.ruoyi.user.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.favorite.mapper.FavoriteMapper;
import com.ruoyi.favorite.domain.Favorite;
import com.ruoyi.favorite.service.IFavoriteService;

/**
 * 用户收藏Service业务层处理
 * 
 * @author 张富饶
 * @date 2025-05-18
 */
@Service
public class FavoriteServiceImpl implements IFavoriteService 
{
    @Autowired
    private FavoriteMapper favoriteMapper;
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private ProductMapper productMapper;
    @Autowired
    private PlaceMapper placeMapper;

    /**
     * 查询用户收藏
     * 
     * @param id 用户收藏主键
     * @return 用户收藏
     */
    @Override
    public Favorite selectFavoriteById(Long id)
    {
//        Favorite favorite =
        Favorite favorite = favoriteMapper.selectFavoriteById(id);
        System.err.println(favorite);
        User user1 = favorite.getUser();
        Long userId1 = user1.getUserId();
//        Long userId = favorite.getUserId();
        System.err.println(userId1);
        User user = userMapper.selectUserByUserId(userId1);
        System.err .println(user);
        favorite.setUser(user);
        Product product = favorite.getProduct();
        Long id1 = product.getId();
        Product product1 = productMapper.selectProductById(id1);
        favorite.setProduct(product1);
        Place place = favorite.getPlace();
        Long id2 = place.getId();
        Place place1 = placeMapper.selectPlaceById(id2);
        favorite.setPlace(place1);
//        favoriteMapper.selectFavoriteById(id).setUser(userMapper.selectUserByUserId());
        System.err.println(favorite);
        return favorite;
    }

    /**
     * 查询用户收藏列表
     * 
     * @param favorite 用户收藏
     * @return 用户收藏
     */
    @Override
    public List<Favorite> selectFavoriteList(Favorite favorite)
    {
        return favoriteMapper.selectFavoriteList(favorite);
    }

    /**
     * 新增用户收藏
     * 
     * @param favorite 用户收藏
     * @return 结果
     */
    @Override
    public int insertFavorite(Favorite favorite)
    {
        favorite.setCreateTime(DateUtils.getNowDate());
        return favoriteMapper.insertFavorite(favorite);
    }

    /**
     * 修改用户收藏
     * 
     * @param favorite 用户收藏
     * @return 结果
     */
    @Override
    public int updateFavorite(Favorite favorite)
    {

        return favoriteMapper.updateFavorite(favorite);
    }

    /**
     * 批量删除用户收藏
     * 
     * @param ids 需要删除的用户收藏主键
     * @return 结果
     */
    @Override
    public int deleteFavoriteByIds(Long[] ids)
    {
        return favoriteMapper.deleteFavoriteByIds(ids);
    }

    /**
     * 删除用户收藏信息
     * 
     * @param id 用户收藏主键
     * @return 结果
     */
    @Override
    public int deleteFavoriteById(Long id)
    {
        return favoriteMapper.deleteFavoriteById(id);
    }
}
